package cn.sdhuijin.service;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.sdhuijin.dao.UserDao;
import cn.sdhuijin.model.User;
import cn.sdhuijin.utils.CommonUtil;

/**
 * @author sunp@sdhuijin.cn:
 * @version 创建时间：2015年5月7日 上午11:32:21 类说明
 */

@Service
@Transactional
public class UserServiceImpl implements UserService {

	@Inject
	private UserDao userDao;

	@Override
	public void BatchImport(List<List<Object>> llo) throws Exception {
		if (llo != null) {
			for (int i = 1; i < llo.size(); i++) {
				User user = new User();
				String userName = llo.get(i).get(1).toString().trim();
				if (CommonUtil.allIsNotEmpty(userName)) {
					List<User> existedStandardItem = userDao
							.findByName(userName);
					if (existedStandardItem.size() == 0) {
						user.setName(userName);
						String userPassword = llo.get(i).get(2).toString()
								.trim();
						if (CommonUtil.allIsNotEmpty(userPassword)) {
							user.setPass(userPassword);
						}
						user.setTelephone(llo.get(i).get(3).toString().trim());
						userDao.save(user);
					}
				}

			}
		}

	}

	@Override
	public boolean Login(String userName, String userPWD) {
		boolean flag = false;
		List<User> users = userDao.findByNameAndPass(userName, userPWD);
		if (users.size() > 0) {
			flag = true;
		}
		return flag;
	}

}
